import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  page = "/member-service/member/user/page",
  get = "/member-service/member/user/get",
  save = "/member-service/member/user/save",
  update = "/member-service/member/user/update",
  delete = "/member-service/member/user/delete",
  batchDelete = "/member-service/member/user/batchDelete",
  frozenBatch = "/member-service/member/user/frozenBatch",
  adjustUserPoint = "/member-service/member/user/adjustPoint",
  // 账户明细
  pageAccountDetail = "/member-service/accountDetail/page",
}

export const pageAccountDetail = (params) => {
  return defHttp.get({ url: Api.pageAccountDetail, params })
}

export const pageMemberUser = (params) => {
  return defHttp.get({ url: Api.page, params })
}

export const saveOrUpdateUser = (params, isUpdate) => {
  const url = isUpdate ? Api.update : Api.save
  return defHttp.post({ url: url, params })
}

export const getUserDetails = (params) => {
  return defHttp.get({ url: Api.get, params })
}

export const deleteUser = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteUser = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDelete, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

/**
 * 冻结解冻
 */
export const frozenBatch = (params, handleSuccess) => {
  return defHttp.put({ url: Api.frozenBatch, params }).then(() => {
    handleSuccess()
  })
}

export const adjustUserPoint = (params) => {
  return defHttp.put({ url: Api.adjustUserPoint, params }, { joinParamsToUrl: true })
}
